<template>
	<view class="wanlshop-category-container">
		<!-- 导航条 -->
		<view class="cu-custom" :style="{ height: $wanlshop.wanlsys().height + 'px' }">
			<view class="cu-bar fixed bg-white solid-bottom" :style="{
					height: $wanlshop.wanlsys().height + 'px',
					paddingTop: $wanlshop.wanlsys().top + 'px'
				}">
				<view class="action" @tap="handleGroups" v-if="false">
					<text class="wlIcon-pintuan3"></text>
					<!-- <view class="cu-tag badge">拼</view> -->
				</view>
				<!-- <view v-show="isBack" @tap="setBack">
					<u-icon name="arrow-left" color="#000" size="40"></u-icon>
				</view> -->
				<view class="ml12 mt8" @click="$wanlshop.back(1)">
					<u-icon name="arrow-left" size="36"></u-icon>
				</view>

				<view class="search-form round">
					<text class="wlIcon-sousuo1 text-bold"></text>
					<swiper class="search-swiper placeholder" vertical autoplay circular interval="3000">
						<swiper-item @tap="productSearch('')">搜索商品、类目</swiper-item>
						<swiper-item v-for="(item, index) in common.modulesData.searchModules" :key="item.keywords"
							@tap="productSearch(item.keywords)">
							{{ item.keywords }}
						</swiper-item>
					</swiper>
				</view>
				<!-- #ifndef MP -->
				<view class="action" @tap="showModal('menu')" v-if="false">
					<text class="wlIcon-gengduo"></text>
					<!-- {{( statistics.notice.notice + statistics.notice.order + statistics.notice.chat + statistics.order.pay + statistics.order.delive + statistics.order.receiving + statistics.order.evaluate + cart.cartnum )}} -->
					<!-- <view class="cu-tag badge bg-orange" v-if=" statistics.notice.notice +
								statistics.notice.order +
								statistics.notice.chat +
								statistics.order.pay +
								statistics.order.delive +
								statistics.order.receiving +
								statistics.order.evaluate +
								cart.cartnum >
								0
						"></view> -->
				</view>
				<!-- #endif -->
			</view>
		</view>
		<!-- 加载类目 -->
		<view class="navBox">
			<view class="" v-for="(item,index) in navList" @click="navClick(item,index)">
				<view class="forNavBox">
					<image class="navImg" :src="item.img1" mode="" v-if="index == navIndex"></image>
					<image class="navImg" :src="item.img2" mode="" v-else></image>
					<view class="mt16 f28 fb" :class="{'info':navIndex !== index}">
						{{item.name}}
					</view>
				</view>
			</view>
		</view>
		<wanl-shop-classify :mainHeight="height" :categoryStyle="parseInt(3)" :shopId='1' :categoryData="categoryData"
			:adverData="common.adData.categoryAdverts" />
		<!-- 模态框 -->
		<view class="WANL-MODAL">
			<view class="cu-modal top-modal" :class="modalName == 'menu' ? 'show' : ''" @tap="hideModal">
				<view class="wanl-modal-menu cu-dialog" @tap.stop="">
					<wanl-direct @change="hideModal" />
				</view>
			</view>
			<!-- 分享 -->
			<view class="cu-modal bottom-modal" :class="modalName == 'share' ? 'show' : ''" @tap="hideModal">
				<view class="cu-dialog" @tap.stop="">
					<wanl-share :scrollAnimation="scrollAnimation" shareTitle="我发现了一个很好的线上购物商城，这是商城类目"
						shareText="品质好而且很省钱如果自己在上面购买，每年可以省下1%~40%的钱" :image="$wanlshop.appstc('/common/logo.png')"
						:href="common.appConfig.domain + '/pages/category?QRtype=category'" @change="hideModal" />
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import wanlShopClassify from '@/components/wanl-shop/classify';
	export default {
		data() {
			return {
				categoryData: [],
				navIndex: 0,
				height: 0,
				modalName: null,
				scrollAnimation: 300,
				navList: [{
					img1: 'https://img.aibbyp.com/wechatUser/category1/az1.png',
					img2: 'https://img.aibbyp.com/wechatUser/category1/az2.png',
					name: '安装',
					id: 0,
				}, {
					img1: 'https://img.aibbyp.com/wechatUser/category1/wx1.png',
					img2: 'https://img.aibbyp.com/wechatUser/category1/wx2.png',
					name: '维修',
					id: 1,
				}, {
					img1: 'https://img.aibbyp.com/wechatUser/category1/gc1.png',
					img2: 'https://img.aibbyp.com/wechatUser/category1/gc2.png',
					name: '工程',
					id: 2,
				}, {
					img1: 'https://img.aibbyp.com/wechatUser/category1/jz1.png',
					img2: 'https://img.aibbyp.com/wechatUser/category1/jz2.png',
					name: '家政',
					id: 3,
				}, ],
			};
		},
		components: {
			wanlShopClassify
		},
		computed: {
			...mapState(['common', 'statistics', 'cart'])
		},
		mounted() {

		},
		onLoad(option) {
			if (option.type) {
				this.navIndex = Number(option.type)
			}

		},
		created() {
			let wanlsys = this.$wanlshop.wanlsys();
			// #ifdef APP-PLUS
			this.height = wanlsys.windowHeight + wanlsys.windowBottom - wanlsys.height;
			// #endif
			// #ifdef H5
			this.height = wanlsys.windowHeight + wanlsys.windowBottom - wanlsys.height - 50;
			// #endif
			// #ifdef MP
			this.height = wanlsys.windowHeight - wanlsys.height;
			// #endif
			// #ifdef MP-WEIXIN
			wx.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage', 'shareTimeline']
			});
			// #endif
			this.getworker()
		},
		methods: {
			navClick(item, index) {
				this.navIndex = index
				this.getworker()
			},
			getworker() {
				this.$api.get({
					url: '/worker/goods/lists',
					data: {
						type: this.navIndex + 1
					},
				}).then(res => {
					console.log(res);
					res.forEach(a => {
						a.childlist = a.goods
						a.name = a.title
						a.childlist.forEach(b => {
							b.childlist = b.goods
							b.name = b.title
							b.image = b.cover_image
						})
					})
					this.categoryData = res
					console.log(this.categoryData);
					console.log(this.common);
				})
			},
			setBack() {
				uni.switchTab({
					url: '/pages/tabbarcompotant/index/landlord'
				});
				// this.$store.commit('common/setBackof',false);
			},
			// 弹出层
			showModal(name) {
				// 滚动下分享
				if (name == 'share' && this.modalName != 'share') {
					setTimeout(() => {
						this.scrollAnimation = 300;
					}, 300);
				}
				this.modalName = name;
			},
			hideModal(name) {
				if (name) {
					this.showModal(name);
				} else {
					this.modalName = null;
				}
			},
			handleGroups() {
				this.$wanlshop.to('/pages/apps/groups/index');
			},
			productSearch(text) {
				this.$wanlshop.to(`/pages/page/search?type=goods&page=craftsman&keywords=${text}`, 'fade-in', 100);
			}
		}
	};
</script>

<style lang="scss" scoped>
	.navBox {
		display: flex;
		padding: 20rpx 0rpx;

		.forNavBox {
			display: flex;
			flex-direction: column;
			align-items: center;
			margin: 0 34rpx;
		}

		.navImg {
			width: 84rpx;
			height: 84rpx;
			border-radius: 50%;
		}
	}

	.wanlshop-category-container {
		background-image: url('https://img.aibbyp.com/wechatUser/category1/bac1.png');
		background-size: 100% 332rpx;
		background-repeat: no-repeat;

		.cu-custom {
			background: transparent;

			.cu-bar {
				background: transparent;
			}

			.solid-bottom::after {
				border-bottom: none;
			}
		}
	}

	.cu-custom .cu-bar {
		z-index: 99;
	}

	.cu-bar .action {
		position: relative;
	}

	/* #ifdef MP */
	.cu-bar .search-form {
		margin: 0 0 0 25rpx;
	}

	/* #endif */
</style>